# 在搜狗（https://www.sogou.com/）搜索天气预报
import time
from selenium import webdriver
from selenium.webdriver.common.by import By


class SoGou:
    def __init__(self):  # 初始化打开谷歌浏览器进入搜狗搜索
        self.driver = webdriver.Chrome()
        self.driver.get('https://www.sogou.com/')

    def quit(self, seconds=2):  # 初始化关闭
        time.sleep(seconds)
        self.driver.quit()

    def sogou_get(self):
        self.driver.find_element(By.ID, 'query').send_keys('天气预报')  # 找到搜索框元素的id,并且输入内容
        self.driver.find_element(By.ID, 'stb').click()  # 找到搜狗搜索元素的id,然后点击
        time.sleep(2)  # 延时2s
        print(self.driver.title)  # 输出标题内容
        self.driver.maximize_window()  # 浏览器最大化


# 调用
if __name__ == '__main__':
    case = SoGou()
    case.sogou_get()
    case.quit()
